import type { RouteRecordRaw } from 'vue-router'
import { useStorage } from '@vueuse/core'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAppUeStore = defineStore('appUeStore', () => {
  const isCollapse = ref(false)
  const theme = ref('default')
  function changeCollapsed() {
    isCollapse.value = !isCollapse.value
  }
  return {
    changeCollapsed,
    isCollapse,
    theme,
  }
})

// 标签页
export function useTabPageStore() {
  const NotAddTabList = ['/not-found', '/login']
  const tabList = useStorage<RouteRecordRaw[]>('tabList', [])

  const addTab = (route: any) => {
    if (NotAddTabList.includes(route.path)) {
      return
    }
    if (tabList.value.some(item => item.path === route.path)) {
      return
    }
    tabList.value.push(route)
  }

  const removeTab = (route: any) => {
    tabList.value = tabList.value.filter(
      item => item.name !== route.name,
    )
  }

  const removeAllTab = () => {
    tabList.value = []
  }
  return {
    addTab,
    tabList,
    removeTab,
    removeAllTab,
  }
}
